package com.yyds.controller;

import com.yyds.common.MyJSON;
import com.yyds.common.R;
import com.yyds.pojo.TravelWay;
import com.yyds.service.TravelWayService;
import com.yyds.vo.WayTravelWayEchartPieVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/admin/travel/way")
public class TravelWayController {
    @Autowired
    private TravelWayService travelWayService;

    @RequestMapping("/list")
    public MyJSON<TravelWay> selectAllTravelWayController(@RequestParam Map<String,Object> params){


        //注意这里使用map来接收参数 前端传的不定参数 都可以封装到map中

        return travelWayService.selectAllTravelWayService(params);

    }
    @PostMapping("/deletetravelway")
    public R deleteTravelWayController (Integer way_tid) {
        //根据Id删除出行方式信息
       int result = travelWayService.deleteTravelWayService(way_tid);

        if (result==1){
            return R.ok();
        }else{
            return R.error();
        }

    }

    //添加出行方式信息
    @PostMapping("/addtravelway")
    public R addTravelWayController(TravelWay travelWay) {

        System.out.println(travelWay);

        int result = travelWayService.addTravelWayService(travelWay);

        if (result == 1) {
            return R.ok();
        } else {
            return R.error();
        }
    }
    //修改出行方式信息
    @PostMapping("/updatetravelway")
    public R updateTravelWayController(TravelWay travelWay) {
        int result = travelWayService.updateTravelWayService(travelWay);

        if (result == 1) {
            return R.ok();
        } else {
            return R.error();
        }

    }


    //删除部分疫苗种类
    @RequestMapping("/deletealltravelway")
    public R deleteAllTravelWayController(String str) {
        System.out.println("deleteAllTravelWayController str" + str);
        Integer i = travelWayService.deleteAllTravelWayService(str);
        return i > 0 ? R.ok() : R.error();
    }
    //查询出行方式
    @RequestMapping("/queryWayTravelWayEchartPie")
    public R queryWayTravelWayController(){
        List<WayTravelWayEchartPieVo> list = travelWayService.queryWayTravelWayService();
        return R.ok().data("pie", list);
    }
}
